'use strict';

const Service = require('egg').Service;

class groupService extends Service {

  /*
  * 查询list 
  * Method: get
  * path: /xxxx
  */

  async index(query, fields, options) {
    const results = await this.ctx.model.Group.find(query, fields, options)
    return results
  }

  /*
  * collection信息
  * obj: 查询的key 和 value  {id: id}
  * 
  */
  async show(query) {
    const results = await this.ctx.model.Group.findOne(query)
                          .populate({path: 'createUser'})
    return results
  }

  /*
  * 创建
  * Method: post
  * path: /xxxx
  */
  async create(data) {
    const result = await this.ctx.model.Group.create(data)
    return result
  }

  /*
  * 修改更新
  * Method: put
  * path: /xxxx/:id
  */
  async update(query, data) {
    const result = await this.ctx.model.Group.update(query, data)
    return result
  }

  /*
  * 删除
  * Method: DELETE
  * obj: {key: keyValue}
  */
  async destroy(query) {
    const result = await this.ctx.model.Group.remove(query)
    return result
  }
}

module.exports = groupService
